//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "NonCentralChiSquareDistribution.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (Double df, Double ncp) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phNonCentralChiSquareDistribution = NULL;
#endif
        QuantLib::Real _df = (QuantLib::Real)ValueHelper::Convert (df); //d
        QuantLib::Real _ncp = (QuantLib::Real)ValueHelper::Convert (ncp); //d
        _ppNonCentralChiSquareDistribution = new boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution> (new QuantLib::NonCentralChiSquareDistribution ( _df,  _ncp ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNonCentralChiSquareDistribution = NULL;
#endif
	_ppNonCentralChiSquareDistribution = &childNative;
    
}
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (QuantLib::NonCentralChiSquareDistribution& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phNonCentralChiSquareDistribution = NULL;
#endif
	_ppNonCentralChiSquareDistribution = new boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution> (&childNative);
    
    _NonCentralChiSquareDistributionOwner = owner;
    
}

Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (CNonCentralChiSquareDistribution^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNonCentralChiSquareDistribution = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNonCentralChiSquareDistribution = new boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNonCentralChiSquareDistribution = NULL;
#endif
	if (!t->IsSubclassOf(CNonCentralChiSquareDistribution::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (QuantLib::Handle<QuantLib::NonCentralChiSquareDistribution>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phNonCentralChiSquareDistribution = &childNative;
	_ppNonCentralChiSquareDistribution = &static_cast<boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution>>(childNative.currentLink());
    
    _NonCentralChiSquareDistributionOwner = owner;
}
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (QuantLib::Handle<QuantLib::NonCentralChiSquareDistribution> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phNonCentralChiSquareDistribution = &childNative;
	_ppNonCentralChiSquareDistribution = &static_cast<boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::CNonCentralChiSquareDistribution (QuantLib::NonCentralChiSquareDistribution childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNonCentralChiSquareDistribution = NULL;
#endif
	_ppNonCentralChiSquareDistribution = new boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution> (new QuantLib::NonCentralChiSquareDistribution (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::~CNonCentralChiSquareDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppNonCentralChiSquareDistribution != NULL)
    {
	    delete _ppNonCentralChiSquareDistribution;
        _ppNonCentralChiSquareDistribution = NULL;
    }
}
Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::!CNonCentralChiSquareDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppNonCentralChiSquareDistribution != NULL)
    {
	    delete _ppNonCentralChiSquareDistribution;
    }
}
QuantLib::NonCentralChiSquareDistribution& Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::GetReference ()
{
    if (_ppNonCentralChiSquareDistribution == NULL) throw REFNEW NativeNullException ();
	return **_ppNonCentralChiSquareDistribution;
}
boost::shared_ptr<QuantLib::NonCentralChiSquareDistribution>& Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::GetShared ()
{
    if (_ppNonCentralChiSquareDistribution == NULL) throw REFNEW NativeNullException ();
	return *_ppNonCentralChiSquareDistribution;
}
QuantLib::NonCentralChiSquareDistribution* Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::GetPointer ()
{
    if (_ppNonCentralChiSquareDistribution == NULL) throw REFNEW NativeNullException ();
	return &**_ppNonCentralChiSquareDistribution;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NonCentralChiSquareDistribution>& Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::GetHandle ()
{
	if (_phNonCentralChiSquareDistribution == NULL)
	{
		_phNonCentralChiSquareDistribution = new Handle<QuantLib::NonCentralChiSquareDistribution> (*_ppNonCentralChiSquareDistribution);
	}
	return *_phNonCentralChiSquareDistribution;
}
#endif
bool Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution::HasNative () 
{
	return (_ppNonCentralChiSquareDistribution != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::INonCentralChiSquareDistribution^ Cephei::QL::Math::Distributions::CNonCentralChiSquareDistribution_Factory::Create (Double df, Double ncp)
{
    return REFNEW CNonCentralChiSquareDistribution ( df,  ncp);
}
